package com.dayaokeji.rhythmschoolstudent.client.common.exam.subject_type;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.exam.subject_type.utils.OnClickFirstSubjectCallback;
import com.dayaokeji.rhythmschoolstudent.client.common.exam.subject_type.utils.ScoreUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 *  考试结果
 */
public class ExamResultFragment extends BaseSubjectFragment {

    private static final String EXTRA_GET_SCORE = "get_score";
    private static final String EXTRA_TOTAL_SCORE = "total_score";

    @BindView(R.id.tv_get_scroe)
    TextView tvGetScore;
    @BindView(R.id.tv_total_scroe)
    TextView tvTotalScore;
    @BindView(R.id.v_line)
    View vLine;

    private double getScore;
    private double totalScore;

    public static ExamResultFragment newInstance(double getScore,double totalScore) {
        
        Bundle args = new Bundle();
        args.putDouble(EXTRA_GET_SCORE,getScore);
        args.putDouble(EXTRA_TOTAL_SCORE,totalScore);
        ExamResultFragment fragment = new ExamResultFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    protected View onCreate(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_exam_result, container, false);
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        init();
    }

    private void init() {
        getScore = getArguments().getDouble(EXTRA_GET_SCORE);
        totalScore = getArguments().getDouble(EXTRA_TOTAL_SCORE);
        setupView();
        setupViewData();
    }

    private void setupView() {
        vLine.setRotation(25);
    }

    private void setupViewData() {
        tvGetScore.setText(ScoreUtil.doubleTrans(getScore));
        tvTotalScore.setText(ScoreUtil.doubleTrans(totalScore));
    }

    @OnClick({R.id.btn_show_subject_info})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_show_subject_info:
                if (getActivity() != null) {
                    if (getActivity() instanceof OnClickFirstSubjectCallback) {
                        ((OnClickFirstSubjectCallback) getActivity()).onClick(view);
                    }
                }
                break;
        }
    }
}
